#include "login.h"
#include "mainwindow.h"
#include "ui_login.h"

#include <QMessageBox>

Login::Login(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Login)
{
    ui->setupUi(this);
    setWindowIcon(QIcon(":/res/res_log.png"));
    setWindowTitle("登陆界面");
    setWindowFlags(Qt::MSWindowsFixedSizeDialogHint);
}

Login::~Login()
{
    delete ui;
}

void Login::on_pushButton_login_clicked()//登录按钮槽函数
{
    //接受用户输入：
    QString account = ui->lineEdit_name->text();//用户名
    QString Password = ui->lineEdit_password->text();//密码
    if(account.isEmpty()||Password.isEmpty())
    {
        QMessageBox::critical(this, "错误提示", "用户名和密码输入不能为空！", "关闭");
    }
    else
    {
        if(db.selecting(account,Password))
        {
            MainWindow *M=new MainWindow;
            M->show();
            connect(this,&Login::root,M,&MainWindow::getRoot);
            emit root(account);
            this->hide();
        }
        else
        {
            QMessageBox::critical(this, "错误提示", "用户名或密码输入有误！", "关闭");
        }
    }
}
